"use strict";
/* Controllers */
app.controller("hdfsPathEditController", ['$scope', '$location', '$rootScope', '$q', '$routeParams', 'hdfsPathEditService', function ($scope, $location, $rootScope, $q, $routeParams, hdfsPathEditService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.type = $routeParams.type;
    vm.p.id = $routeParams.id;

    vm.p.depth = 4;
    if(vm.p.type=='5') {
        vm.p.depth = 5;
    }
    function getNewObjectOf(src) {
        return Object.assign({}, src);
    }

    //e_time\s*[\)]?\s*[>|>=|<|<=|=]{1,2}\s*['|"]{1}%s['|"]{1}
    var errorFn = function (result) {
        alert(result);
    };

    //    $scope.validateSql=function(){
    //        console.log("sql"+vm.p.sql)
    //    }

    $scope.getHdfsPath = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data
            } else {
                alert(res.msg);
            }
        };
        return hdfsPathEditService.getHdfsPath(params, procFn, errorFn);
    };

    $scope.hdfsPathSave = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("保存成功！")
            } else {
                alert(response.msg);
            }
        };
        hdfsPathEditService.hdfsPathSave(params, procFn, errorFn);
    };

    //
    if (typeof (vm.p.id) != "undefined" && vm.p.id != null && vm.p.id!='0') {
        $scope.getHdfsPath()
    }


}]);


/* Services */
app.service('hdfsPathEditService', ['ajaxService', function (ajaxService) {

    this.hdfsPathSave = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/hdfsPath/add.do", successFunction, errorFunction);
    };

    this.getHdfsPath = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/hdfsPath/detail.do", successFunction, errorFunction);
    };

}]);

